<%@ include file="/WEB-INF/work/start.jspf"%><html lang="zh-hans">
<head>
<%@ include file="/WEB-INF/jspf/meta.jspf"%>
<title>新增任务</title>
<%@ include file="/WEB-INF/work/css.jspf"%>
<style type="text/css">
.pure-table{
	margin-top:10px;
}
.filter-bar{
	margin-top:5px;
	text-align:center;
}
@media screen and (max-width:600px){
	.table-response.pure-table td:before{
		content: attr(data-label);
		float:left;
		text-transform: uppercase;
		font-weight:bold;
	}
	.table-response.pure-table thead{
		display:none;
	}
	.table-response.pure-table tr{
		display:block;
		margin-bottom:10px;
		border-bottom:2px solid #ddd;
	}
	.table-response.pure-table td{
		display:block;
		text-align:right;
	}
}
.pure-form select{
	height:2.4em;
}
.pure-button-primary{
	margin-top: 18px;
    font-size: 110%;
}
</style>
</head>
<body>
<fmt:parseNumber var="project" integerOnly="true" type="number" value="${param.project}" />
<c:set var="assigned_to" value="assigned-to" />
<c:set var="created_by" value="created-by" />
<fmt:parseNumber var="assignedTo" integerOnly="true" type="number" value="${param[assigned_to]}" />
<fmt:parseNumber var="createdBy" integerOnly="true" type="number" value="${param[created_by]}" />
<c:set var="status" value="${param.status}" />
<div class="filter-bar">
<form method="get" class="pure-form">
<fieldset>
<div class="pure-g">
<div class="pure-u-1-5 pure-u-md-1-5">
<label for="project">项目</label>
<select id="project" name="project" class="pure-u-23-24">
<option value="">所有</option>
	<sql:query var="items" dataSource="${work}">
		select * from simpletask_project order by id desc
	</sql:query>
	<c:forEach var="item" items="${items.rows}">
		<c:choose>
			<c:when test="${item.id==project}">
				<option value="${item.id}" selected="selected">${item.name}</option>
			</c:when>
			<c:otherwise>
				<option value="${item.id}">${item.name}</option>
			</c:otherwise>
		</c:choose>
	</c:forEach>
</select>
</div> 
<div class="pure-u-1-5 pure-u-md-1-5">
<label for="status">状态</label>
<select id="status" name="status" class="pure-u-23-24">
<option value="">所有</option>
	<%
		Map<String,String> allStatus=new LinkedHashMap<String,String>();
		allStatus.put("new","新建");
		allStatus.put("progress","进行中");
		allStatus.put("done","完成");
		allStatus.put("defer","推迟");
		allStatus.put("closed","关闭");
		
		request.setAttribute("allStatus",allStatus);
	%>
	<c:forEach var="item" items="${allStatus}">
		<c:choose>
			<c:when test="${item.key==status}">
				<option value="${item.key}" selected="selected">${item.value}</option>
			</c:when>
			<c:otherwise>
				<option value="${item.key}">${item.value}</option>
			</c:otherwise>
		</c:choose>
	</c:forEach>
</select>
</div> 
<div class="pure-u-1-5 pure-u-md-1-5">
<label for="assigned-to">分配给</label>
<select id="assigned-to" name="assigned-to" class="pure-u-23-24">
<option value="">所有</option>
	<sql:query var="items" dataSource="${work}">
		select distinct b.id,b.username  as name from simpletask_task a inner join auth_user b on b.id=a.assigned_to_id
	</sql:query>
	<c:forEach var="item" items="${items.rows}">
		<c:choose>
			<c:when test="${item.id==assignedTo}">
				<option value="${item.id}" selected="selected">${item.name}</option>
			</c:when>
			<c:otherwise>
				<option value="${item.id}">${item.name}</option>
			</c:otherwise>
		</c:choose>
	</c:forEach>
</select>
</div>
<div class="pure-u-1-5 pure-u-md-1-5">
<label for="created-by">创建人</label>
<select id="created-by" name="created-by" class="pure-u-23-24">
<option value="">所有</option>
	<sql:query var="items" dataSource="${work}">
		select distinct b.id,b.username  as name from simpletask_task a inner join auth_user b on b.id=a.created_by_id
	</sql:query>
	<c:forEach var="item" items="${items.rows}">
		<c:choose>
			<c:when test="${item.id==createdBy}">
				<option value="${item.id}" selected="selected">${item.name}</option>
			</c:when>
			<c:otherwise>
				<option value="${item.id}">${item.name}</option>
			</c:otherwise>
		</c:choose>
	</c:forEach>
</select>
</div>
<div class="pure-u-1-5 pure-u-md-1-5">
<button type="submit" class="pure-u-23-24 pure-button pure-button-primary">搜索</button>
</div>
</div>
</fieldset>
</form>
</div>
<table class="table-response pure-table ui table pure-table-bordered" id="task-list" style="width:100%">
	<thead>
		<tr>
			<th>Id</th>
			<th>Title</th>
			<th>Status</th>
			<th>Created By</th>
			<th>Assigned To</th>
			<!--<th>Created At</th>-->
			<th>Due At</th>
			<!--<th>Done At</th>-->
		</tr>
	</thead>
	<tbody>
		<sql:query var="items" dataSource="${ work }">
select a.*
	,case 
		when a.status = 'progress'
			then 1
		when a.status = 'new'
			then 2
		when a.status = 'defer'
			then 3
		end as sort_order
	,b.name as project_name
	,c.username as created_by
	,d.username as assigned_to
from simpletask_task a
INNER JOIN simpletask_project b on a.project_id = b.id
inner join auth_user c on c.id=a.created_by_id
inner join auth_user d on d.id=a.assigned_to_id
where 1=1 
		<c:if test="${empty status}">
			and (a.status = 'new'
		or a.status = 'progress'
		or a.status = 'defer')
		</c:if>
		<c:if test="${! empty status}">
			and a.status=?
		</c:if>
		<c:if test="${! empty project}">
			and a.project_id=?
		</c:if>
		<c:if test="${! empty assignedTo}">
			and a.assigned_to_id=?
		</c:if>
		<c:if test="${! empty createdBy}">
			and a.created_by_id=?
		</c:if>	
order by sort_order asc
	,a.id desc
		<c:if test="${! empty status}">
			<sql:param value="${status}"></sql:param>
		</c:if>
		<c:if test="${! empty project}">
			<sql:param value="${project}"></sql:param>
		</c:if>
		<c:if test="${! empty assignedTo}">
			<sql:param value="${assignedTo}"></sql:param>
		</c:if>
		<c:if test="${! empty createdBy}">
			<sql:param value="${createdBy}"></sql:param>
		</c:if>	
		</sql:query>
		<c:forEach var="item" items="${items.rows}" varStatus="status">
			<tr class="task-${item.status}">
			<td data-label="ID">${item.id}</td>
			<td data-label="项目名称">[${item.project_name}]${item.title}</td>
			<td data-label="状态">${allStatus[item.status]}</td>
			<td data-label="创建人">${item.created_by}</td>
			<td data-label="分配给">${item.assigned_to}</td>
			<!--<td>{{item.created_at|date:"Y-m-d"}}</td>-->
			<td data-label="最后期限">${item.due_at}</td>
			<!--<td>{{item.done_at|date:"Y-m-d"}}</td>-->
			</tr>
		</c:forEach>
	</tbody>
</table>
<%@ include file="/WEB-INF/jspf/js.jspf"%>
<script type="text/javascript">
/*
 var queryString = {},
	 url='<%=request.getRequestURI()%>';
if (location.search) {
   var qa = location.search.substring(1).split('&');
   for (var i = 0, t = qa.length; i < t; i++) {
	   var item=qa[i].split('=');
	   queryString[item[0]] = item[1]||'';
   }
}


$("select").change(function(){
	var self=$(this),
		q={};
	q[self.attr('id')]=self.val();
	location.href=url+'?'+$.param($.extend(queryString,q));
});
*/
</script>
</body>
</html>